package com.controller;

import com.token.JwtUtil;
import com.vo.ResponseBean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api")
public class LoginController {

    @RequestMapping("/login")
    public ResponseBean login(String username, String password, HttpServletResponse response){
        System.out.println("LoginController.LoginController-username:="+username);

        if ("admin".equals(username)){
            //产生一个令牌
            String tokenString= JwtUtil.generToken(username,null,null);
            System.out.println("LoginController.LoginController-tokenString:="+tokenString);
            //响应头跨域
            response.addHeader("Access-Control-Expose-Headers","token");
            //发送给客户端
            response.addHeader("token",tokenString);
            return new ResponseBean(200,0,null);
        }
        return new ResponseBean(500,0,null);

    }

}
